package com.hackerrank.challenges.utopianidentificationnumber;

import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		in.nextLine();
		for(int n = 0; n < N; n++) {
			if(in.nextLine().matches("[a-z]{0,3}[0-9]{2,8}[A-Z]{3,}"))
				System.out.println("VALID");
			else
				System.out.println("INVALID");
		}
	}
}
